package com.shuzixiangcun.service.admin;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shuzixiangcun.entity.Users;
import com.shuzixiangcun.dao.UsersDao;
import io.swagger.models.auth.In;
import org.apache.catalina.User;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.List;

/**
 * 用户信息表(Users)表服务实现类
 *
 * @author makejava
 * @since 2024-06-24 08:26:21
 */
@Service
public class UsersServiceImpl{

    @Resource
    private UsersDao usersDao;

    public List<Users> getUsersList(String search) {return usersDao.getUsersList(search);}
    public int insertUser(Users user) {
        return usersDao.insertUser(user);
    }



    public int updateByPhone(Users users) {
        return usersDao.updateByPhone(users);
    }





    public Users querybyUsernameAndPassword(String username, String password) {
        return this.usersDao.querybyUsernameAndPassword(username, password);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param userId 主键
     * @return 实例对象
     */

    public Users queryById(Integer userId) {
        return this.usersDao.queryById(userId);
    }

    /**
     * 分页查询
     *
     * @param users       筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */


    /**
     * 新增数据
     *
     * @param users 实例对象
     * @return 实例对象
     */

    public Users insert(Users users) {
        this.usersDao.insert(users);
        return users;
    }

    /**
     * 修改数据
     *
     * @param users 实例对象
     * @return 实例对象
     */

    public int update(Users users) {

        return this.usersDao.update(users);
    }

    /**
     * 通过主键删除数据
     *
     * @param userId 主键
     * @return 是否成功
     */

    public boolean deleteById(Integer userId) {
        return this.usersDao.deleteById(userId) > 0;
    }


    public int addCardId(Users users) {
        return this.usersDao.addCardId(users);
    }


    public int updateByRole(Users user) {
        return this.usersDao.updatByRole(user);
    }


    public PageInfo<Users> getPageInfo(Integer pageNo, Integer pageSize,String search) {
        PageHelper.startPage(pageNo, pageSize,true);
        List<Users> mangerList=usersDao.getUsersList(search);
        return new PageInfo<Users>(mangerList);
    }
}
